package com.group.project.hrms.service.impl;

import com.group.project.hrms.entity.HolidayRecord;
import com.group.project.hrms.mapper.HolidayRecordMapper;
import com.group.project.hrms.service.IHolidayRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class HolidayRecordService implements IHolidayRecordService {

    @Autowired
    private HolidayRecordMapper holidayRecordMapper;

    @Override
    public int insertHolidayRecord(HolidayRecord holidayRecord) {
        return holidayRecordMapper.insert(holidayRecord);
    }

    @Override
    public int deleteHolidayRecord(HolidayRecord holidayRecord) {
        return holidayRecordMapper.deleteByPrimaryKey(holidayRecord);
    }

    @Override
    public int updateHolidayRecord(HolidayRecord holidayRecord) {
        return holidayRecordMapper.updateByPrimaryKey(holidayRecord);
    }

    @Override
    public HolidayRecord selectOneHolidayRecord(HolidayRecord holidayRecord) {
        return null;
    }

    @Override
    public List<HolidayRecord> selectHolidayRecordByYear(int year) {
        Example example = new Example(HolidayRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andLike("appointDate", "%" + year + "%");
        return holidayRecordMapper.selectByExample(example);
    }

    @Override
    public List<HolidayRecord> selectHolidayRecordByMonth(String month) {
        Example example = new Example(HolidayRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orLike("appointDate", "%" + month + "%");
        return holidayRecordMapper.selectByExample(example);
    }

    @Override
    public List<HolidayRecord> selectAllHolidayRecord() {
        return holidayRecordMapper.selectAll();
    }
}
